package com.google.precinct.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class LandingFindPrecinctPanel extends Composite {

	private static WizardFirstPageUiBinder uiBinder = GWT
			.create(WizardFirstPageUiBinder.class);

	interface WizardFirstPageUiBinder extends UiBinder<Widget, LandingFindPrecinctPanel> {
	}

	@UiField
	TextBox precinctNo;

	@UiField
	TextBox area;

	@UiField
	Button precinctSearch;

	@UiField
	Button areaSearch;

	@UiField
	Label error;

	private final MainShell ctr;

	public LandingFindPrecinctPanel(MainShell mainShell) {
		this.ctr = mainShell;
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("precinctSearch")
	void onClickPrecinct(ClickEvent e) {
		String value = precinctNo.getText().trim();
		if (value.length() == 0 ||
				!value.matches("[0-9]+[a-zA-Z]*")) {
			UIUtils.error(error, "Invalid precinct number.\nIt should be something like '1009A'.");
			return;
		}

//		ctr.precinctSearch(value);
	}

	@UiHandler("areaSearch")
	void onClickArea(ClickEvent e) {
		String value = area.getText().trim();
		if (value.length() < 3) {
			UIUtils.error(error, "Invalid area.\nPlease enter more information.");
			return;
		}

//		ctr.areaSearch(value);
	}

}
